package com.example.arithmeticleetcode.leetcode.jan;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2021-01-22 09:26
 **/
public class Demo18 {
}

class OrderedStream {

    private int ptr = 1;
    private String[] arr;

    public OrderedStream(int n) {
        arr = new String[n + 1];
    }

    public List<String> insert(int id, String value) {
        List<String> list = new ArrayList<>();
        if (id == ptr) {
            arr[id] = value;
            for (int i = ptr; i <= arr.length; i++) {
                if (arr[i] == null) break;
                list.add(arr[i]);
                ptr++;
            }
        } else {
            arr[id] = value;
        }
        return list;
    }
}
